/*
 *  $Id: ElementType.cs 1201 2010-11-22 12:22:17Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;
using System.Collections.Generic;

using AgateLib.Geometry;
using AgateLib.DisplayLib;

using Ragima.Helper;
using Ragima.Languages;

namespace Ragima {
    /// <summary>
    /// Класс стихии и её данных.
    /// </summary>
    public class ElementType: INamed {
        private int _num;
        private string _id;
        private Names _name;
        private Color _color;
        private Surface _frame, _mana;
        private ElementType _enemy;

        private ElementType(int num, string id, Color color) {
            _num = num;
            _id = id;
            _name = new Names("element."+id, false);
            _color = color;
            _enemy = null;
        }

        public int Number {
            get { return _num; }
        }

        public string Id {
            get { return _id; }
        }

        public Names Name {
            get { return _name; }
        }
        public Names ManaName {
            get { return this == Neutral ? HealthName : _name; }
        }

        public Color ElementColor {
            get { return _color; }
        }

        public ElementType EnemyElement {
            get { return _enemy; }
            private set { _enemy = value; }
        }

        public Surface Frame {
            get { return _frame; }
        }

        public Surface ManaSymbol {
            get { return _mana; }
        }

        public void LoadSurfaces() {
            _frame = new Surface(GetFrameName());
            _mana = new Surface(GetManaName());
        }

        private string GetFrameName() {
            return Paths.AddFileNameSuffix("frame_.png", _id);
        }
        private string GetManaName() {
            return Paths.AddFileNameSuffix("mana_.png", _id);
        }

        public ElementRelation GetRelationTo(ElementType other) {
            if (other == this)
                return ElementRelation.Self;
            else if (other == _enemy)
                return ElementRelation.Enemy;
            else
                return ElementRelation.Other;
        }

        public const string NeutralId = "neutral";
        public const string LightId = "light";
        public const string DarknessId = "darkness";
        public const string FireId = "fire";
        public const string WaterId = "water";
        public const string EarthId = "earth";
        public const string AirId = "air";

        public static readonly ElementType Neutral = new ElementType(0, NeutralId, 0xe60039.ToColor());
        public static readonly ElementType Light = new ElementType(1, LightId, 0xe6e6e6.ToColor());
        public static readonly ElementType Darkness = new ElementType(2, DarknessId, 0x595959.ToColor());
        public static readonly ElementType Fire = new ElementType(3, FireId, 0xe67300.ToColor());
        public static readonly ElementType Water = new ElementType(4, WaterId, 0x0077ed.ToColor());
        public static readonly ElementType Earth = new ElementType(5, EarthId, 0x00ca18.ToColor());
        public static readonly ElementType Air = new ElementType(6, AirId, 0x00eded.ToColor());
        public static readonly ElementType Health = Neutral;
        public static readonly Names HealthName = new Names("element.health", false);

        public static readonly ElementType[] AllElements = new ElementType[] { Neutral, Light, Darkness, Fire, Water, Earth, Air };
        public static readonly ElementType[] ManaElements = new ElementType[] { Light, Darkness, Fire, Water, Earth, Air };
        public static int Count {
            get { return AllElements.Length; }
        }

        static ElementType() {
            SetEnemyElements(Light, Darkness);
            SetEnemyElements(Fire, Water);
            SetEnemyElements(Earth, Air);
        }

        private static void SetEnemyElements(ElementType e1, ElementType e2) {
            e1.EnemyElement = e2;
            e2.EnemyElement = e1;
        }
    }

    /// <summary>
    /// Отношение между двумя стихиями.
    /// </summary>
    public enum ElementRelation {
        Self,
        Enemy,
        Other
    }

    /// <summary>
    /// Набор из двух фраз, для общей маны и для здоровья.
    /// </summary>
    public class ElementPhrase {
        private Phrase _mana, _health;

        public ElementPhrase(string id) {
            _mana = new Phrase(id);
            _health = new Phrase(id+".health");
        }

        public Phrase GetPhrase(ElementType element) {
            return element == ElementType.Neutral ? _health : _mana;
        }

        public string GetText(ElementType element) {
            return GetPhrase(element).GetText(element.ManaName);
        }
    }
}
